package com.soup.view;

import com.soup.domain.Person;
import com.soup.view.component.Context;
import com.soup.view.component.MeFrame;

import javax.swing.*;
import java.awt.event.ActionEvent;

public class StudentFrame extends MeFrame {


    private JButton bro = new JButton("借书");
    private JButton give = new JButton("还书");
    private JButton save = new JButton("存钱");
    private JButton replace = new JButton("排行榜");


    private Context right = null;

    private MeControl meControl = null;


    public StudentFrame(Login login, Person person) {
        super("学生" , 1000, 600);

        meControl = new MeControl(login,this);

        meControl.setName(person.getName());
        meControl.setState(person.getState());

        meControl.setLocation(850,100);
        context.add(meControl);

        //初始化左边
        context.add(bro,20);
        bro.setBounds(40,60,120,50);

        context.add(give,20);
        give.setBounds(40,130,120,50);

        context.add(save,20);
        save.setBounds(40,200,120,50);

        context.add(replace,20);
        replace.setBounds(40,270,120,50);


        // 左边添加监听器
        bro.addActionListener(this);
        give.addActionListener(this);
        replace.addActionListener(this);
        save.addActionListener(this);
    }

    @Override
    public void doActionPerformed(ActionEvent e) {
        if (right != null){
            context.remove(right);
        }
        if (e.getSource() == bro){
            right = new BroBookFrame(this.getWidth()-400,this.getHeight()-100);
            context.add(right);
            right.setLocation(200,60);
        }else if (e.getSource() == give){
            right = new ReturnFrame(this.getWidth()-400,this.getHeight()-100);
            context.add(right);
            right.setLocation(200,60);
        }else if (e.getSource() == replace){
            right = new TopFrame(this.getWidth()-400,this.getHeight()-100);
            context.add(right);
            right.setLocation(200,60);
        }else if (e.getSource() == save){
            right = new MoneyFrame(this.getWidth()-400,this.getHeight()-100);
            context.add(right);
            right.setLocation(200,60);
        }
    }
}